// race


Promise.race = function(promises) {
    return new Promise((resolve, reject) => {
        let len = promises.length
        let result = []
        if(len == 0) {
            return
        }

        for (let i = 0; i < len; i++) {
            Promise.resolve(promises[i]).then(data => {
                resolve(data)
                return
            }).catch(err => {
                reject(err)
                return
            })
        }
    })
}


let a = function() {
    return new Promise((resolve, rejected) => {
        console.log('123');
        setTimeout(() => {
            resolve('123')
        }, 2000)
    })
}

let b = function() {
    return new Promise((resolve, rejected) => {
        console.log('123');
        setTimeout(() => {
            rejected('333')
        }, 1000)
    })
}



// pro.then(res => {
//     console.log(res);
// })

Promise.race([a(), b()]).then(res => {
    console.log(res);
})